const { recursionFilePath } = require("./util");
const fse = require('fs-extra');
const fs = require("fs");

//文件路径
const targetPath = "../build-0.0.129";
const replacePath = "https://game-zj-cdn.xinghegame.com/qjwx_test/mini_test2_20230109";
//设定大小
const sizeMin = 40 * 1024;
const sizeMax = 90 * 1024;
let count = 0;

fse.removeSync("./cdnFiles.txt");

//大于某一个值，捞出文件
function checkFileSize(path, size) {
    // if (size >= sizeMin) {
    if (size >= sizeMin && size < sizeMax) {
        console.log("size:" + size + "  path:", path);
        const cdnPath = path.replace(targetPath, replacePath);
        console.log("cdnPath:" + cdnPath);
        // fs.writeFileSync('./cdnFiles.txt', cdnPath)

        fs.writeFile('./cdnFiles.txt', cdnPath + "\n", { flag: "a" }, () => {
            count++;
            console.log("count:", count);
        });
    }
}

recursionFilePath(targetPath, (filePath) => {
    fs.stat(filePath, function (error, stats) {
        if (error) {
            callback("file size error");
        } else {
            //文件大小
            checkFileSize(filePath, stats.size);
        }
    })
});





